'''
爬取梨视频，克服防盗链
'''
import requests
url = "https://www.pearvideo.com/video_1758639"
heards = {
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.88 Safari/537.36"
    #溯源
    ,"Referer": url
}

cont_id = url.split("_")[1]
#虚拟地址
# https://video.pearvideo.com/mp4/adshort/20220416/1650275285861-15862864_adpkg-ad_hd.mp4
#实际地址
# videoUrl = "https://video.pearvideo.com/mp4/adshort/20220416/cont-{}-15862864_adpkg-ad_hd.mp4".format(cont_id)
#请求地址
respurl = "https://www.pearvideo.com/videoStatus.jsp?contId={}&mrd=0.9378700842799497".format(cont_id)

resp = requests.get(url=respurl, headers=heards)
dic = resp.json()
virtul_Url = dic['videoInfo']['videos']['srcUrl']
videoUrl = virtul_Url.replace(dic['systemTime'], f'cont-{cont_id}')
print(videoUrl)

with open("./文件/a.mp4", mode="wb") as f:
    f.write(requests.get(videoUrl).content)
